<template lang="">
  <div class="pages">
    <!-- 头部导航 -->
    <!-- <van-nav-bar title="UKey" :fixed="true" :placeholder="true" /> -->
    <!-- 用户信息 -->
    <div class="user-info">
      <div class="info-box" @click="login">{{ encryption }}</div>
      <HeadCom
        :isBnb="isBnb"
        :address="address"
        :info="info"
        :encryption="encryption"
      />
    </div>
    <!-- <div class="user-info">
      <div class="info-box" @click="login">{{ encryption }}</div>
      <div class="info-right">
        <div class="info-box" @click="toMining">
          {{ t("homeRight") }}UKey：{{ info.uddNum || "0" }}
        </div>
        <van-popover
          v-model:show="isShowI18n"
          :actions="actionsList"
          placement="bottom-end"
          @select="onI18nSelect"
        >
          <template #reference>
            <img
              style="width: 26px; height: 26px; margin-left: 15px"
              src="@/static/fill-earth.png"
              mode="widthFix"
              alt=""
            />
          </template>
        </van-popover>
        <img
              style="width: 26px; height: 26px; margin-left: 15px"
              src="@/static/menu.png"
              mode="widthFix"
              alt=""
              @click="showRight = true"
            /> -->
    <!-- <van-popover
          v-model:show="isShowMenu"
          :actions="menuActionsList"
          placement="bottom-end"
          @select="onMenuSelect"
        >
          <template #reference>
            <img
              style="width: 26px; height: 26px; margin-left: 15px"
              src="@/static/menu.png"
              mode="widthFix"
              alt=""
            />
          </template>
        </van-popover> -->
    <!-- </div> -->
    <!-- </div> -->
    <!-- 轮播图 -->
    <div class="swipe-box">
      <img
        v-if="locale === 'zh'"
        style="width: 100%; height: 100%"
        src="@/static/banner-zh.png"
        alt=""
      />
      <img
        v-if="locale === 'en'"
        style="width: 100%; height: 100%"
        src="@/static/banner-en.png"
        alt=""
      />
      <img
        v-if="locale === 'ts'"
        style="width: 100%; height: 100%"
        src="@/static/banner-ts.png"
        alt=""
      />
    </div>
    <!-- 投资收益 -->
    <div class="investment-title">
      <span style="font-size: 18px"
        >{{ t("titleLeft") }}
        <span style="color: #f0bc0f"
          >1.5{{ t("bei") }}{{ t("out") }}</span
        ></span
      >
      <span style="font-size: 15px">{{ t("free") }}1000{{ t("mei") }}UKey</span>
    </div>
    <!-- 投资100U -->
    <div class="investment-box">
      <div class="investment-money">100 USDT</div>
      <div
        v-if="!info.vipInvset"
        class="investment-btn"
        @click="investmentClick(0)"
      >
        {{ t("immediateInvestment") }}
      </div>
      <div v-else class="investment-btn">
        {{ t("invested") }}
      </div>
    </div>
    <!-- 收益菜单 -->
    <div class="menu-box">
      <div class="menu-left">
        <div class="left-top">2{{ t("bei") }}{{ t("out") }}</div>
        <div class="left-bottom">
          <span
            style="
              font-size: 18px;
              font-family: PingFangSC-Medium;
              font-weight: Medium;
              margin-bottom: 10px;
            "
            >{{ t("supernode") }}</span
          >
          <span
            style="font-size: 15px; font-family: Impact; font-weight: Regular"
            >500 USDT</span
          >
          <span
            v-if="!info.nodeInvset"
            class="authorization-btn"
            @click="investmentClick(1)"
            >{{ t("immediateAuthorization") }}</span
          >
          <span v-else class="authorization-btn">{{ t("invested") }}</span>
          <span
            style="
              font-size: 12px;
              font-family: PingFangSC-Medium;
              font-weight: Regular;
            "
            >{{ t("free") }}5000{{ t("mei") }}UKey</span
          >
        </div>
      </div>
      <div class="menu-right">
        <div class="right-box" style="margin-bottom: 14px">
          <div class="left-box">
            <span style="margin-bottom: 12px">{{ t("staticIncome") }}</span>
            <span
              style="font-size: 15px; font-family: Impact; font-weight: Regular"
              >{{ info.staticEarning || "0" }} USDT</span
            >
          </div>
          <!-- <div class="right-right">
            {{ t("withdrawIncome") }}
          </div> -->
        </div>
        <div class="right-box">
          <div class="left-box">
            <span style="margin-bottom: 12px">{{ t("dynamicIncome") }}</span>
            <span
              style="font-size: 15px; font-family: Impact; font-weight: Regular"
              >{{ info.dynamicEarning || "0" }} USDT</span
            >
          </div>
          <!-- <div class="right-right">
            {{ t("withdrawIncome") }}
          </div> -->
        </div>
      </div>
    </div>
    <!-- 出局进度 -->
    <div class="out-progress">
      <span class="out-head">
        <div>
          <span>{{ t("outgoingProgress") }}</span>
          <span class="rule" @click="isOutgoingStatement = true">{{
            t("rule")
          }}</span>
          <!-- <img
            style="width: 16px; margin-left: 10px"
            src="@/static/help.png"
            mode="widthFix"
            alt=""
            @click="isOutgoingStatement = true"
          /> -->
        </div>
        <img
          style="width: 16px"
          src="@/static/switch.png"
          mode="widthFix"
          alt=""
          @click="isSwitch = !isSwitch"
        />
      </span>
      <!-- 100档 -->
      <div v-if="!isSwitch" class="out-body">
        <div class="body-top">
          <span>{{
            getOutProgress(info.vipInvset?.investNum, info.vipInvset?.outNum)
          }}</span>
          <span
            >VIP{{ info.vipInvset?.state === 0 ? t("notOut") : t("out") }}</span
          >
        </div>
        <div class="body-center">
          <div class="center-bg"></div>
          <div
            :style="`width: ${getOutProgress(
              info.vipInvset?.investNum,
              info.vipInvset?.outNum
            )}`"
            class="center-content"
          ></div>
        </div>
        <div class="body-bottom">{{ info.vipInvset?.outNum }}USDT</div>
      </div>
      <!-- 500档 -->
      <div v-else class="out-body">
        <div class="body-top">
          <span>{{
            getOutProgress(info.nodeInvset?.investNum, info.nodeInvset?.outNum)
          }}</span>
          <span
            >{{ t("node")
            }}{{ info.nodeInvset?.state === 0 ? t("notOut") : t("out") }}</span
          >
        </div>
        <div class="body-center">
          <div class="center-bg"></div>
          <div
            :style="`width: ${getOutProgress(
              info.nodeInvset?.investNum,
              info.nodeInvset?.outNum
            )}`"
            class="center-content"
          ></div>
        </div>
        <div class="body-bottom">{{ info.nodeInvset?.outNum }}USDT</div>
      </div>
    </div>
    <!-- 我的直推 -->
    <div class="direct-box">
      <div class="direct-head">
        <div>
          <span>{{ t("straightPush") }}</span>
          <span class="rule" @click="isDirectPush = true">{{ t("rule") }}</span>
          <!-- <img
            style="width: 16px; margin-left: 10px"
            src="@/static/help.png"
            mode="widthFix"
            alt=""
            @click="isDirectPush = true"
          /> -->
        </div>
        <span
          class="invite-log"
          @click="isBnb ? '' : router.push('/inviteLog')"
          >{{ t("invitationRecord") }}</span
        >
      </div>
      <div class="direct-body">
        <div class="body-box">
          <div class="body-top">
            {{ info.directNum || "0" }}{{ t("people") }}
          </div>
          <div class="body-bottom">{{ t("straightPush") }}</div>
        </div>
        <div class="body-box">
          <div class="body-top">
            {{ info.validDirectNum || "0" }}{{ t("people") }}
          </div>
          <div class="body-bottom">{{ t("effectiveDirectPush") }}</div>
        </div>
        <div class="body-box">
          <div class="body-top">
            {{
              info.validDirectNum > 10
                ? t("tenGenerations")
                : validDirectNumListData[info.validDirectNum] || "0"
            }}
          </div>
          <div class="body-bottom">{{ t("echelonIncome") }}</div>
        </div>
        <div class="body-box">
          <div class="body-top">{{ info.lineUp || "0" }}</div>
          <div class="body-bottom">{{ t("inLine") }}</div>
        </div>
      </div>
    </div>
    <!-- 收益记录 -->
    <!-- <div class="log-box">
      <div class="log-head">
        <span class="head-left">{{ t("incomeRecord") }}</span>
        <span class="head-right" @click="isBnb ? '' : router.push('/log')">{{
          t("moreRecords")
        }}</span>
      </div>
      <div class="log-body">
        <table v-if="recordList.length !== 0">
          <tr>
            <th>{{ t("address") }}</th>
            <th>{{ t("time") }}</th>
            <th>{{ t("amount") }}</th>
          </tr>
          <tr v-for="item in recordList" :key="item.id">
            <td>{{ plusXing(item.sendAddress) }}</td>
            <td>{{ item.updateTime }}</td>
            <td>{{ item.incomeNum }}USDT</td>
          </tr>
        </table>
        <van-empty v-else :description="t('noDataYet')" />
      </div>
    </div> -->
    <!-- 我的邀请 -->
    <div class="invite-box">
      <div class="invite-head">{{ t("myInvitation") }}</div>
      <div class="invite-body">
        <div class="invite-title">{{ t("invitationLink") }}</div>
        <div class="invite-url">
          https://api.ukeynetwork.com?address={{ address }}
        </div>
        <div class="invite-btn" @click="copyLink">
          {{ t("copyInvitationLink") }}
        </div>
      </div>
    </div>
    <!-- 项目介绍 -->
    <!-- <div class="introduce-box">
      <div class="introduce-head">{{ t("projectIntroduction") }}</div>
      <div class="introduce-body">
        <div>
          <div class="introduce-title">UKEY</div>
          <p>{{ t("introduce1") }}</p>
        </div>
        <div>
          <div class="introduce-title">UKEY BOX</div>
          <p>{{ t("introduce2") }}</p>
        </div>
        <div>
          <div class="introduce-title">UKEY Wallet</div>
          <p>{{ t("introduce3") }}</p>
        </div>
        <div>
          <div class="introduce-title">UKEY Swap</div>
          <p>{{ t("introduce4") }}</p>
        </div>
      </div>
    </div> -->
    <!-- 出局提示弹窗 -->
    <div>
      <van-overlay
        v-model:show="isOutgoingStatement"
        @click="isOutgoingStatement = false"
      >
        <div class="content-box">
          <div class="cross"></div>
          <div class="vertical"></div>
          <div class="content-body">
            <div class="body-tip">{{ t("outgoingStatement") }}</div>

            <div v-if="info.curOut < 4" class="body-num">
              <div class="current-box">
                <span :class="info.curOut !== 1 ? 'num-box' : 'current-num'"
                  >1</span
                >
                <div v-if="info.curOut === 1" class="num-title">
                  <span class="sanjiao"></span>
                  <div class="text">{{ t("currentOut") }}</div>
                </div>
              </div>
              <div class="current-box">
                <span :class="info.curOut !== 2 ? 'num-box' : 'current-num'"
                  >2</span
                >
                <div v-if="info.curOut === 2" class="num-title">
                  <span class="sanjiao"></span>
                  <div class="text">{{ t("currentOut") }}</div>
                </div>
              </div>
              <div class="current-box">
                <span :class="info.curOut !== 3 ? 'num-box' : 'current-num'"
                  >3</span
                >
                <div v-if="info.curOut === 3" class="num-title">
                  <span class="sanjiao"></span>
                  <div class="text">{{ t("currentOut") }}</div>
                </div>
              </div>
              <div class="current-box">
                <span :class="info.curOut !== 4 ? 'num-box' : 'current-num'"
                  >4</span
                >
                <div v-if="info.curOut === 4" class="num-title">
                  <span class="sanjiao"></span>
                  <div class="text">{{ t("currentOut") }}</div>
                </div>
              </div>
              <span class="num-box">5</span>
              <span style="display: flex; align-items: center">········</span>
              <span class="num-box">N</span>
            </div>

            <div v-else class="body-num">
              <span class="num-box">{{ info.curOut - 3 }}</span>
              <span class="num-box">{{ info.curOut - 2 }}</span>
              <span class="num-box">{{ info.curOut - 1 }}</span>
              <div class="current-box">
                <span class="current-num">{{ info.curOut }}</span>
                <div class="num-title">
                  <span class="sanjiao"></span>
                  <div class="text">{{ t("currentOut") }}</div>
                </div>
              </div>
              <span class="num-box">{{ info.curOut + 1 }}</span>
              <span style="display: flex; align-items: center">········</span>
              <span class="num-box">N</span>
            </div>
            <div class="body-foot">
              <div>{{ t("outTip1") }}</div>
              <div>{{ t("outTip2") }}</div>
              <div>{{ t("outTip3") }}</div>
            </div>
          </div>
        </div>
      </van-overlay>
    </div>
    <!-- 团队说明弹窗 -->
    <div>
      <van-overlay v-model:show="isDirectPush" @click="isDirectPush = false">
        <div class="direct-push">
          <div class="cross"></div>
          <div class="vertical"></div>
          <div class="direct-body">
            <div class="body-tip">{{ t("teamStatement") }}</div>
            <div class="body-table">
              <table>
                <tr>
                  <th>{{ t("name") }}</th>
                  <th>{{ t("condition") }}</th>
                  <th>{{ t("proportion") }}</th>
                </tr>
                <tr v-for="(item, index) in ruleList" :key="index">
                  <td>{{ item.name }}</td>
                  <td>{{ item.condition }}</td>
                  <td>{{ item.proportion }}</td>
                </tr>
              </table>
            </div>
            <div class="direct-foot">*{{ t("footTitle") }}</div>
          </div>
        </div>
      </van-overlay>
    </div>
    <!-- 绑定上级弹窗 -->
    <div>
      <div class="binding-superior">
        <van-popup
          v-model:show="isBindingSuperior"
          :close-on-click-overlay="false"
        >
          <div class="cross"></div>
          <div class="vertical"></div>
          <div class="binding-body">
            <div class="body-tip">{{ t("bindingParent") }}</div>
            <van-field
              v-model="bindingParentValue"
              type="textarea"
              :placeholder="t('superiorWalletAddressTip')"
            />
            <div class="binding-btn" @click="submitBinding">
              {{ t("deterministicBinding") }}
            </div>
          </div>
        </van-popup>
      </div>
    </div>

    <!-- 右侧菜单弹出框 -->
    <!-- <van-popup
      v-model:show="showRight"
      position="right"
      :style="showRightStyle"
    >
    <div>
      <div class="head-box">
        <img src="@/static/logo2x.png" alt="" srcset="">
        <div class="head-title">UKey</div>
      </div>

      <div>
        <div class="do-checkout-right">
          <img src="" alt="">
          <span class="do-checkout-right-text">首页</span>
        </div>
        <div class="no-checkout-right">
          <img src="" alt="">
          <span class="no-checkout-right-text">我的挖矿</span>
        </div>
        <div class="no-checkout-right">
          <img src="" alt="">
          <span class="no-checkout-right-text">收益记录</span>
        </div>
        <div class="no-checkout-right">
          <img src="" alt="">
          <span class="no-checkout-right-text">项目介绍</span>
        </div>
      </div>
    </div>
  </van-popup> -->
  </div>
</template>
<script setup>
import { ref, reactive, onMounted, watch } from "vue";
import { useRouter } from "vue-router";
import useClipboard from "vue-clipboard3";
import {
  showSuccessToast,
  showLoadingToast,
  closeToast,
  showFailToast,
} from "vant";
import { useI18n } from "vue-i18n";
import App from "@/store/ethers.js";
import * as HomeApi from "@/api/home";
import HeadCom from "@/components/HeadCom.vue";
import { ruleListData, validDirectNumListData } from "@/utils/enumerationData";

const { t, locale } = useI18n();
const { toClipboard } = useClipboard();
const router = useRouter();
const app = new App();
let result = "";

const encryption = ref(""); // 右侧导航连接钱包或登录文字
const isOutgoingStatement = ref(false); // 是否显示出局弹窗
const isDirectPush = ref(false); // 是否显示团队说明弹窗
// const isShowI18n = ref(false); // 展开语言切换列表
// const isShowMenu = ref(false); // 展开菜单切换列表
const isBindingSuperior = ref(false); // 是否显示绑定上级弹窗
const isSwitch = ref(false); // 切换节点或者VIP出局进度
const address = ref(""); // 钱包地址
const info = ref({}); // 首页数据
const recordList = ref([]); // 首页收益记录数据
const bindingParentValue = ref("0x29212A590be11eCfEccF7647D587cEDdddbdAC58"); // 绑定上级输入框的值
// const actionsList = ref(actionsListData); // 国际化切换下拉列表
// const menuActionsList = ref(menuListData); // 菜单切换下拉列表
const ruleList = reactive(ruleListData); // 团队说明列表数据
const isBnb = ref(false); // 是否在币安链
// const showRight = ref(false); // 是否展开右侧弹窗
// const showRightStyle = ref({
//   width: "50%",
//   height: "100%",
// });

// 监听语言切换
watch(locale, (nData) => {
  if (nData) {
    encryption.value = t("connectedWallet");
    if (!address.value) return;
    encryption.value = plusXing(address.value);
  }
});

// 初始化
onMounted(() => {
  encryption.value = t("connectedWallet");
  locale.value = "en";
});

// 页面初始化
const init = async () => {
  try {
    app.init().then((res) => (result = res));
    if (result === "error") return showFailToast(t("walletConnectionFailure"));
    await app.onAccountsChanged(initInfoAccounts);
    await app.onChainChanged(initInfoChain);
    const chainIdInfo = await app.getNetwork();
    if (chainIdInfo.chainId !== 56) {
      showFailToast(t("chainTip"));
      isBnb.value = true;
      return;
    }
    isBnb.value = false;
    address.value = await app.getWalletAddress();
    if (
      window.localStorage.getItem("token") &&
      window.localStorage.getItem("walletAddress") === address.value
    ) {
      encryption.value = plusXing(address.value);
      getInfo();
      getRecord();
      console.log(info.value.isBindLev, "info.value.isBindLev");
    }
  } catch (error) {
    console.log(error, "error");
    showFailToast(t("initializationFailure"));
  }
};
const initInfoAccounts = async () => {
  isBnb.value = false;
  address.value = await app.getWalletAddress();
  window.localStorage.setItem("token", "");
  encryption.value = t("connectedWallet");
  info.value = {};
  recordList.value = [];
  address.value = "";
  isBindingSuperior.value = false;
};

const initInfoChain = async (chainId) => {
  isBnb.value = false;
  address.value = await app.getWalletAddress();
  window.localStorage.setItem("token", "");
  encryption.value = t("connectedWallet");
  info.value = {};
  recordList.value = [];
  address.value = "";
  isBindingSuperior.value = false;
  if (chainId !== "0x38") {
    showFailToast(t("chainTip"));
    isBnb.value = true;
    return;
  }
};

// 计算出局进度百分比
const getOutProgress = (investNum, outNum) => {
  if (investNum >= outNum) {
    return "100%";
  } else {
    const num = (investNum / outNum) * 100;
    return `${
      !isNaN(num)
        ? String(num).split(".")
          ? String(num).split(".")[0]
          : num
        : "--"
    }%`;
  }
};

// 点击登录
const login = async () => {
  init();
  if (!(encryption.value === t("connectedWallet"))) return;
  if (isBnb.value) {
    showFailToast(t("chainTip"));
    return;
  }
  showLoadingToast({
    message: `${t("connectedWallet")}...`,
    forbidClick: true,
  });
  // 获取随机数
  address.value = await app.getWalletAddress();
  const res = await HomeApi.getNonce({
    walletAddress: address.value,
  });
  //获取签名
  let signature = "";
  try {
    signature = await app.signature(res.data.content);
  } catch (error) {
    return;
  }
  //登录
  address.value = String(address.value).toLowerCase();
  const res2 = await HomeApi.goLogin({
    walletAddress: address.value,
    signature: signature,
    nonce: res.data.content,
  });
  // //存token
  encryption.value = plusXing(address.value);
  await window.localStorage.setItem("token", res2.data.content.token);
  await window.localStorage.setItem(
    "walletAddress",
    res2.data.content.walletAddress
  );
  closeToast();
  getInfo();
  getRecord();
};

// 获取首页数据
const getInfo = async () => {
  if (isBnb.value) {
    showFailToast(t("chainTip"));
    return;
  }
  const res = await HomeApi.getInfo();
  if (res.data.code === 200) {
    info.value = res.data.content;

    // if (info.value.isBindLev === 0 && window.location.search?.split('=')[1]) {
    //   const addressUrl = window.location.search.split('=')[1];
    //   bindingParentValue.value = addressUrl;
    // }
    if (info.value.isBindLev === 0) {
      if (window.location.search?.split("=")[1]) {
        let addressUrl = "0x29212A590be11eCfEccF7647D587cEDdddbdAC58";
        if (window.location.search.split("&").length > 1) {
          addressUrl = window.location.search.split("=")[1].split("&")[0];
        }
        bindingParentValue.value = addressUrl;
      }
      isBindingSuperior.value = true;
    }
  }
};

// 点击确定绑定上级
const submitBinding = async () => {
  if (bindingParentValue.value.replace(/(^\s*)|(\s*$)/g, "") !== "") {
    const res = await HomeApi.bindPre({
      walletAddress: bindingParentValue.value,
    });
    if (res.data.code === 200) {
      isBindingSuperior.value = false;
      showSuccessToast(t("successBindingSuperior"));
    }
    getInfo();
  }
};

// 获取收益记录
const getRecord = async () => {
  if (isBnb.value) {
    showFailToast(t("chainTip"));
    return;
  }
  const res = await HomeApi.getRecord({
    pageNum: 1,
    pageSize: 5,
  });
  recordList.value = res.data.content.rows;
};

// 提现收益
// const cashOut = (type) => {
//   if (isBnb.value) {
//     showFailToast(t("chainTip"));
//     return;
//   }
//   showConfirmDialog({
//     title: t("warmReminder"),
//     message: t("confirmWithdrawal"),
//     confirmButtonText: t("confirm"),
//     cancelButtonText: t("cancel"),
//   })
//     .then(async () => {
//       // on confirm
//       if (info.value.holdAPPLE === 0) return showToast(t("withdrawalFail"));
//       const res = await HomeApi.extract({
//         param: type,
//       });
//       console.log(res, "res");
//     })
//     .catch(() => {
//       // on cancel
//     });
// };

// 点击投资
const investmentClick = async (type) => {
  console.log(window.localStorage.getItem("token"), "token");
  console.log(window.localStorage.getItem("walletAddress"), "walletAddress");
  console.log(address.value, "address");
  if (isBnb.value) {
    showFailToast(t("chainTip"));
    return;
  }
  if (
    window.localStorage.getItem("token") &&
    window.localStorage.getItem("walletAddress") === address.value
  ) {
    showLoadingToast({
      message: t("investmentTip"),
      duration: 0,
      forbidClick: true,
    });
    // const collectionAdr = "0x9Eb9b5D5fCF0ffEEc44fF61Ff279c65833dc59f0"; // 转账接收地址
    const collectionAdr = "0x05Bca4E7d634421199B5D273A048408af014447A"; // 转账接收地址
    const walletAdr = address.value; // 查询余额的钱包地址
    // const contractAdr = "0x9Eb9b5D5fCF0ffEEc44fF61Ff279c65833dc59f0"; // 合约地址
    const contractAdr = "0x55d398326f99059ff775485246999027b3197955"; // 合约地址
    const transferNum = type === 0 ? 100 : 500;
    // const transferNum = type === 0 ? 0.1 : 0.2;
    // const transferNum = 0;
    if (walletAdr === "") {
      showFailToast(t("investmentFailTip"));
      return;
    }
    const res = await HomeApi.setSaveOrder({
      type,
      entryWalletAddress: collectionAdr,
    });
    if (res.data.code === 200) {
      try {
        await app.getBalance(contractAdr, walletAdr).then((BalanceRes) => {
          if (Number(BalanceRes) < transferNum)
            showFailToast(t("getBalanceFail"));
          app
            .transfer(contractAdr, collectionAdr, transferNum)
            .then((transferRes) => {
              if (transferRes === "error") closeToast();
              if (transferRes.hash && transferRes.wait) {
                HomeApi.setRechargeState({
                  id: res.data.content.id,
                  hash: transferRes.hash,
                }).then(() => {
                  showLoadingToast({
                    message: `${t("transferSuccess")}...`,
                    duration: 0,
                    forbidClick: true,
                  });
                  transferRes.wait().then(() => {
                    closeToast();
                    showSuccessToast(t("investmentSuccess"));
                    getInfo();
                    getRecord();
                    // window.location.reload();
                  });
                });
              }
            })
            .catch(() => {
              closeToast();
            });
        });
      } catch (error) {
        console.log(error, "error");
        closeToast();
      }
    } else if (res.data.code === 999) {
      showFailToast(t("investmentFailure"));
      return;
    } else if (res.data.code === 100) {
      showFailToast(t("systemBusy"));
    }
  } else {
    login();
  }
};

// 复制事件
const copyLink = (e) => {
  if (isBnb.value) {
    showFailToast(t("chainTip"));
    return;
  }
  e.stopPropagation();
  // toClipboard(`http://192.168.2.40:8081?address=${address.value}`);
  toClipboard(`https://api.ukeynetwork.com?address=${address.value}`);
  showSuccessToast(t("successfulReplication"));
};

// 选择语言
// const onI18nSelect = (e) => {
//   locale.value = e.value;
//   console.log(t("simplifiedChinese"), "e");
// };

// 选择菜单
// const onMenuSelect = (e) => {
//   switch (e.value) {
//     // case "1":
//     //   router.push("/");
//     //   break;
//     case "2":
//       toMining();
//       break;
//     default:
//       break;
//   }
//   locale.value = e.value;
//   console.log(t("simplifiedChinese"), "e");
// };

// 点击前往挖矿页面
// const toMining = () => {
//   if (isBnb.value) {
//     showFailToast(t("chainTip"));
//     return;
//   }
//   if (localStorage.token && localStorage.walletAddress === address.value) {
//     console.log("dsadasdsad");
//     router.push(`/mining?uddNum=${info.value.uddNum}`);
//   } else {
//     showFailToast(t("toMiningFail"));
//   }
// };

// 格式化钱包地址
const plusXing = (str) => {
  let xing = "";
  for (let i = 0; i < 4; i++) {
    xing += "*";
  }
  return str.substring(0, 5) + xing + str.substring(str.length - 3);
};
</script>
<style scoped lang="scss">
@import "./homeView.scss";
</style>
